#coding: utf-8
'''
Работа с XML c помощью DOM
'''

import xml.dom.minidom as XML

#file = open('Files\\xml1.xml')

#DOM
try:
    document = XML.parse('Files\\xml1.xml')
except:
    print ('Bad parsing...')

descriptions = document.getElementsByTagName('description')

for description in descriptions:
    print (description.firstChild.data.strip()) #получение значения узла

items = document.getElementsByTagName('item')

for item in items:
    print (item.getAttribute('num')) #получение значения атрибута

node = document.createElement('recipe') #добавление узла документу
text = document.createTextNode('This third recipe')

child = document.createElement('child')
textChild = document.createTextNode('This text of child')
child.appendChild(textChild)

node.appendChild(child)

node.setAttribute('description', 'This is description')

node.appendChild(text)
document.childNodes[0].appendChild(node)

print(document.toxml())

print (document.TEXT_NODE)